void ReverseStr(char* str, int left, int right) //[left,right]
{
	while (left < right)
	{
		::swap(str[left], str[right]);
		left++;
		right--;
	}
}
int main()
{
	char str[100] = { 0 };
	//scanf("%s", str);
	fgets(str, sizeof(str)-1, stdin); //读取的时候把换行符也读进去了！！！

	int len = strlen(str);
	str[len-1] = '\0'; //    \n->\0

	ReverseStr(str, 0, len-2);//整体逆置
	printf("%s\n", str);

	//hello world 123
	//整体逆置：321 dlorw olleh
	//局部逆置：123 world hello
	              
	int start = 0, end = 0;
	while(str[start])
	{
		end = start;
		while (str[end] && str[end] != ' ')
			end++;
		//[start,end)
		ReverseStr(str, start, end-1);
		start = end+1;
	}	
	printf("%s\n", str);
	return 0;
}